﻿<template>
  <a-modal
    title="新增门诊订单详情"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="订单编号 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入订单编号 " v-decorator="['orderId']" />
        </a-form-item>
        <a-form-item label="处方ID " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入处方ID " v-decorator="['presId']" />
        </a-form-item>
        <a-form-item label="系统分类 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入系统分类 " v-decorator="['sysClass']" />
        </a-form-item>
        <a-form-item label="项目ID " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入项目ID " v-decorator="['itemId']" />
        </a-form-item>
        <a-form-item label="套餐编码 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入套餐编码 " v-decorator="['packageCode']" />
        </a-form-item>
        <a-form-item label="套餐名称 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入套餐名称 " v-decorator="['packageName']" />
        </a-form-item>
        <a-form-item label="会员等级 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入会员等级 " v-decorator="['customerLevel']" />
        </a-form-item>
        <a-form-item label="折扣类型 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入折扣类型 " v-decorator="['rebateType']" />
        </a-form-item>
        <a-form-item label="折扣描述 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入折扣描述 " v-decorator="['rebateDescribe']" />
        </a-form-item>
        <a-form-item label="原价 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入原价 " v-decorator="['originalAmount']" />
        </a-form-item>
        <a-form-item label="支付金额 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入支付金额 " v-decorator="['payAmount']" />
        </a-form-item>
        <a-form-item label="支付折扣 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入支付折扣 " v-decorator="['payRebate']" />
        </a-form-item>
        <a-form-item label="状态 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入状态 " v-decorator="['status']" />
        </a-form-item>
        <a-form-item label="扩展字段 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展字段 " v-decorator="['field01']" />
        </a-form-item>
        <a-form-item label="扩展字段 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展字段 " v-decorator="['field02']" />
        </a-form-item>
        <a-form-item label="扩展字段 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展字段 " v-decorator="['field03']" />
        </a-form-item>
        <a-form-item label="扩展字段 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展字段 " v-decorator="['field04']" />
        </a-form-item>
        <a-form-item label="扩展字段 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展字段 " v-decorator="['field05']" />
        </a-form-item>
        <a-form-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择创建时间" v-decorator="['creatceDate']" @change="onChangecreatceDate"/>
        </a-form-item>
        <a-form-item label="创建者Id" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入创建者Id" v-decorator="['createUserId']" />
        </a-form-item>
        <a-form-item label="创建者名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入创建者名称" v-decorator="['createUserName']" />
        </a-form-item>
        <a-form-item label="更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择更新时间" v-decorator="['modifyDate']" @change="onChangemodifyDate"/>
        </a-form-item>
        <a-form-item label="修改者Id" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入修改者Id" v-decorator="['modifyUserId']" />
        </a-form-item>
        <a-form-item label="修改者名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入修改者名称" v-decorator="['modifyUserName']" />
        </a-form-item>
        <a-form-item label="删除时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择删除时间" v-decorator="['deleteDate']" @change="onChangedeleteDate"/>
        </a-form-item>
        <a-form-item label="删除者ID" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入删除者ID" v-decorator="['deleteUserId']" />
        </a-form-item>
        <a-form-item label="删除者姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入删除者姓名" v-decorator="['deleteUserName']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    OutpOrderDetailAdd
  } from '@/api/modular/main/OutpOrderDetailManage'

  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        creatceDateDateString: '',
        modifyDateDateString: '',
        deleteDateDateString: '',
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            values.creatceDate = this.creatceDateDateString
            values.modifyDate = this.modifyDateDateString
            values.deleteDate = this.deleteDateDateString
            OutpOrderDetailAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      onChangecreatceDate(date, dateString) {
        this.creatceDateDateString = dateString
      },
      onChangemodifyDate(date, dateString) {
        this.modifyDateDateString = dateString
      },
      onChangedeleteDate(date, dateString) {
        this.deleteDateDateString = dateString
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
